﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Basic_sprite_code
{
    class Dragon:Sprite
    {
        public Apprentice summoner; // target object
        public bool guard;          // guarding?
        public bool slain;          // dead?
        public bool attacking;      // attacking?
        public int animCounter;     // for tracking sprite animation
        public float deathChance;

        public Texture2D pic1;
        public Texture2D pic2;

        public Dragon(DarkLordsApprentice g, Apprentice a, Vector2 position, bool isGuard, int magicBoost)
            : base(g, "Dragon1", position, new Vector2(175, 200))
        {
            summoner = a;
            guard = isGuard;
            slain = false;
            attacking = false;
            animCounter = 0;
            deathChance = 0.10f - 0.10f * (magicBoost / 100f);
        }

        public override void Update(GameTime gameTime)
        {
            if (!game.gamePaused)
            {
                if (slain)
                {
                    if (animCounter > 60)
                    {
                        game.Components.Remove(this);
                        summoner.currDragons--;
                    }
                    image = game.Content.Load<Texture2D>("DragonSlain");
                    animCounter++;
                }
                else if (attacking)
                {
                    switch (animCounter)
                    {
                        case 0:
                            image = game.Content.Load<Texture2D>("DragonFire1");
                            animCounter++;
                            break;
                        case 20:
                            image = game.Content.Load<Texture2D>("DragonFire2");
                            animCounter++;
                            break;
                        case 40:
                            image = game.Content.Load<Texture2D>("DragonFire3");
                            animCounter++;
                            break;
                        case 60:
                            image = game.Content.Load<Texture2D>("DragonFire4");
                            animCounter++;
                            break;
                        case 70:
                            game.Components.Add(new Fire(game, new Vector2(position.X - 100 * scale, position.Y), 1, 25));
                            game.Components.Add(new Fire(game, new Vector2(position.X - 150 * scale, position.Y), 1, 50));
                            game.Components.Add(new Fire(game, new Vector2(position.X - 200 * scale, position.Y), 1, 25));
                            animCounter++;
                            break;
                        case 80:
                            attacking = false;
                            animCounter = 0;
                            break;
                        default:
                            animCounter++;
                            break;
                    }
                }
                else
                {
                    switch (animCounter)
                    {
                        case 0:
                            image = game.Content.Load<Texture2D>("Dragon1");
                            animCounter++;
                            break;
                        case 40:
                            image = game.Content.Load<Texture2D>("Dragon2");
                            animCounter++;
                            break;
                        case 80:
                            animCounter = 0;
                            break;
                        default:
                            animCounter++;
                            break;
                    }
                }

                if (guard)
                {
                    scale = 1.0f;
                }
                else
                {
                    float posScale = (position.Y - 150.0f) / 300.0f;
                    scale = 0.25f + posScale * 0.75f;
                }

                base.Update(gameTime);
            }
        }
    }
}
